<%@ page import="com.interfaces.*" %>
<%@ page import="com.core.sysDict.SysDictJsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>招保信息</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <%
    	String path = request.getContextPath();
            path = "/".equals(path)?"":path;
            request.setAttribute("path", path);
            String sysDictJson=SysDictJsp.getSysDictJson(session);
    %>
    <script type="text/javascript">
        var path = "${path}";
    </script>

    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${path}/public/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${path}/public/font-awesome-4.7.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${path}/public/ionicons/ionicons.min.css">
    <!-- Select2 -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/select2/select2.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.css">
    <!-- bootstrap datepicker -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/datepicker/datepicker3.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/AdminLTE.min.css">
    
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect.
    -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/skins/_all-skins.min.css">

    <link rel="stylesheet" href="${path}/css/common.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="${path}/js/json2.js"></script>
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body >
<div class="container">
            <div class="row">
                 <div class="col-md-4">
                    <div class="form-group">
                        <label for="firstPersonName">1号人姓名</label>
                        <input type="text" class="form-control" id="firstPersonName"autoComplete='off' >
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="pinyinName">姓名拼音</label>
                        <input type="text" class="form-control" id="pinyinName" >
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="txtnumber">其余人数</label>
                        <input type="text" class="form-control" id="txtnumber">
                    </div>
                </div>
                
            </div>
            <div class="row">
            	<div class="col-md-4">
                    <div class="form-group">
                        <label for="incomingDate">入境日期</label>
                        <input type="text" class="form-control" id="incomingDate">
                    </div>
                </div>
                 <div class="col-md-4">
                    <div class="form-group">
                        <label for="leaveDate">出境日期</label>
                        <input type="text" class="form-control" id="leaveDate">
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="sendAgentId">送签社</label>
                        <select class="form-control select2" id="sendAgentId">
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="visaType">签证类型</label>
                        <select class="form-control" id="visaType"></select>
                    </div>
                </div>

            </div>
            <div class="row">
            	 <div class="col-md-4">
                    <div class="form-group"id="isStateNorthCountry1">
                        <label for="isStateNorthCountry">要在冲绳和东北6县哪个城市住宿(目前7个城市)</label>
                        <select  class="form-control" id="isStateNorthCountry"></select>
                    </div>
                </div>
                 <div class="col-md-4">
                    <div class="form-group"id="isPastCome1">
                        <label for="isPastCome">过去是否来过</label>
                        <select  class="form-control" id="isPastCome">
                        	<option value="#" selected = "selected">==请选择==</option>
                       		<option value="0">否</option>
                       		<option value="1">是</option>
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group"id="pastCameRecord1">
                        <label for="pastCameRecord">过去访问的记录</label>
                        <select  class="form-control" id="pastCameRecord">
                        	
                        </select>
                    </div>
                </div>
                
            </div>
            <div class="row">
                <div class="col-md-12">
                    <button type="submit" class="btn btn-primary" id="btnAdd">保 存</button>
                </div>
            </div>
<!-- ./wrapper -->
</div>
<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="${path}/public/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${path}/public/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${path}/public/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- Select2 -->
<script src="${path}/public/adminlte/plugins/select2/select2.full.min.js"></script>
<!-- SlimScroll -->
<script src="${path}/public/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${path}/public/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${path}/public/adminlte/dist/js/app.min.js"></script>
<!-- 判空和输入检测 -->
<script src="${path}/js/sysDict.js"></script>
<script src="${path}/js/PYtranslate.js"></script>
<!-- bootstrap datepicker -->
<script src="${path}/public/adminlte/plugins/datepicker/bootstrap-datepicker.js"></script>
<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. Slimscroll is required when using the
     fixed layout. -->
<!-- page script -->
<script>
	var url = window.location.search;
	var arr=url.split('&');
	var curid = "tab_"+arr[arr.length-1];
	console.info(curid);
	function formatRepo (repo) {
      if (repo.loading) {return repo.text;}
      return repo.text+"("+repo.id+")";
    }
    function formatRepoSelection (repo) {
    return repo.text ; 
    }
$(function () {
	var sysDict='<%=sysDictJson%>';
	var re = JSON.parse(sysDict);
	getSelect($("#visaType"),'1002',null,re,0);
	getSelect($("#isStateNorthCountry"),'1004',null,re,0);
	getSelect($("#pastCameRecord"),'1005',null,re,0);
	$("#sendAgentId").select2({
	language: "zh-CN",
	width: "100%",
  	ajax: {
        url: "${path}<%=TravelAgentController.URL_SEARCHSENDAGENT%>",
        dataType: 'json',
        delay: 1000,
        type:"post",
        data: function (params) {
        params.page = params.page || 1;
          return {
            sendAgentCode: params.term, // 关键字
            curPage: params.page, 
            pageSize: 10,
	        singlePage: 0          
          };
        },
        processResults: function (data, params) {
          params.page = params.page || 1;
          return {
            results: data.items,//items:数据 data.total_count:总记录数,items中，字段id为option中的value值，
            pagination: {
              more: (params.page * 10) < data.total_count //页数*每页记录数小于总记录数时，可记录下拉
            }
          };
        },
        cache: true
      },
      escapeMarkup: function (markup) { return markup; },
      minimumInputLength: 0,
      templateResult: formatRepo,
      templateSelection: formatRepoSelection
	});
	$('#incomingDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
    $('#leaveDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
    $('#addDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
    $("#isStateNorthCountry1").hide();
	$("#isPastCome1").hide();
	$("#pastCameRecord1").hide();
	$("#visaType").change(function(){
		if($(this).val()=="#"||$(this).val()==0||$(this).val()==1||$(this).val()==2){
			$("#isStateNorthCountry1").hide();
			$("#isPastCome1").hide();
			$("#pastCameRecord1").hide();
		}else if($(this).val()==3){
			$("#isStateNorthCountry1").show();
			$("#isPastCome1").show();
			if($(isPastCome).val()=="1"){
				$("#pastCameRecord1").show();
			}
		}
	})
	$("#isPastCome").change(function(){
		if($(this).val()=="0"){
			$("#pastCameRecord1").hide();
		}else if($(this).val()=="1"){
			$("#pastCameRecord1").show();
		}
	})
	
	$('#firstPersonName').on("input",function() { 
	var temp =$("#firstPersonName").val();
	var res=ConvertPinyin(temp); 
   	$('#pinyinName').val(res);  
	}); 
	$("#btnAdd").click(function () {
		if(confirm("确定保存并提交所选项目?")){  
		var firstPersonName =$("#firstPersonName").val();
		if(firstPersonName == ""){
            alert("请选择一号人姓名");
            return false;
        } 
        var pinyinName =$("#pinyinName").val();
        if(pinyinName == ""){
            alert("请输入拼音名字");
            return false;
        } 
        var txtnumber = $("#txtnumber").val();
        console.info(txtnumber)
        if(txtnumber == ""){
            alert("请输入人数");
            return false;
        } 
        var incomingDate = $("#incomingDate").val();
         if(incomingDate == ""){
            alert("请选择入境日期");
            return false;
        } 
        
        var leaveDate = $("#leaveDate").val();
         if(leaveDate == ""){
            alert("请选择出境日期");
            return false;
        }else if(leaveDate<incomingDate){
        	alert("出境日期不能早于入境日期!!");
        	return false;
        } 
        
        var sendAgentId = $("#sendAgentId").val();
         if(sendAgentId == ""||sendAgentId==null){
            alert("请输入送签社");
            return false;
        } 
        var visaType = $("#visaType").val();
         if(visaType == "#"){
            alert("请输入签证类型");
            return false;
        } 
        var state =1;
        var returnReportState=0; 
       var isStateNorthCountry2= $("#isStateNorthCountry").val();
        if(visaType=="#"||visaType=="0"||visaType=="1"||visaType=="2"){isStateNorthCountry2="#";}  
        var isPastCome2= $("#isPastCome").val();
        if(visaType=="#"||visaType=="0"||visaType=="1"||visaType=="2"){isPastCome2="#";}  
        var pastCameRecord2= $("#pastCameRecord").val();
        if(isPastCome2=="#"){pastCameRecord2="#"}  
        if(visaType=="3"&& isPastCome2=="#"){
			alert("请选择过去过去是否来过!!") ;
			return false;       
        }
        if (visaType=="3"&& isStateNorthCountry2=="#"){
            alert("请选择要在那个县居住!!") ;
            return false;
        }
        $.ajax({
            url:"${path}<%=GuaranteeController.URL_ADD_UPDATE%>",
            type:"post",
            data:{
            	firstPersonName:firstPersonName,
            	pinyinName:pinyinName,
            	number:txtnumber,
                incomingDate:incomingDate,
				leaveDate:leaveDate,
				visaType:visaType,
				sendAgentId:sendAgentId,
				state:state,
				isPastCome:isPastCome2,
				pastCameRecord:pastCameRecord2,
				isStateNorthCountry:isStateNorthCountry2,
				returnReportState:returnReportState
            },
            success:function(result){
                var re = JSON.parse(result);
                if(re.returnCode=="0"){
                	var guaranteeId = re.nowId;
                	console.info(re.nowId+"NowID");
                	alert("新增招保信息成功！");
                	var url= window.location.search;
                	var arr = url.split('&');
                	parent.refresh(arr[arr.length-1]);
                    var VisaInfoID=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
                    console.info(guaranteeId);
    	 			//parent.addTab({title: "修改签证信息", url:"${path}<%=GuaranteeController.URL_GOTO_UPDATE_PAGE%>?id="+guaranteeId+"&"+VisaInfoID+"&"+curid, id: VisaInfoID, close: true, single:true});
                	//parent.justClose(arr[arr.length-2]);
                	parent.closeAndActiveTab(arr[arr.length-2],arr[arr.length-1]);
                }else if(re.returnCode=="101"){
                    alert("出境日期不能大于入境日期!")
                }
                else{
                    alert(re.msg);
                }
            },
            error:function(request) {      // 设置表单提交出错
                alert(request);  //登录错误提示信息
            }
        });
        return false;
        }
     });
});

</script>
</body>
</html>
